package cn.openea.perpartner.meily.web.controller;

import cn.openea.perpartner.common.core.web.domain.AjaxResult;
import cn.openea.perpartner.meily.web.entity.CourseCategory;
import cn.openea.perpartner.meily.web.entity.dto.CourseCategoryDTOFactory;
import cn.openea.perpartner.meily.web.entity.vo.CourseCategoryEditVo;
import cn.openea.perpartner.meily.web.service.ICourseCategoryService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;


/**
 * 课程分类
 *
 * @author ysk
 * @email zane_ysk@qq.com
 */
@RestController
@RequestMapping("/course/category")
public class CourseCategoryController {

    @Resource
    private ICourseCategoryService courseCategoryService;

    @GetMapping("/list/{parentId}")
    public AjaxResult list(@PathVariable Long parentId) {
        List<CourseCategory> goodsSupplyChainList = courseCategoryService.getListByParentId(parentId);
        return AjaxResult.success(goodsSupplyChainList);
    }

    @GetMapping("/tree/list")
    public AjaxResult treeList() {
        List<CourseCategoryDTOFactory.CategoryTreeDTO> categoryTreeDTOS = courseCategoryService.queryCategoryTreeList();
        return AjaxResult.success(categoryTreeDTOS);
    }

    @GetMapping("/info/{id}")
    public AjaxResult info(@PathVariable Long id) {
        CourseCategory courseCategory = courseCategoryService.getById(id);
        return AjaxResult.success(courseCategory);
    }

    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody @Valid CourseCategoryEditVo editVo) {
        courseCategoryService.edit(editVo);
        return AjaxResult.success();
    }

    @PostMapping("/add")
    public AjaxResult add(@RequestBody @Valid CourseCategoryEditVo editVo) {
        courseCategoryService.add(editVo);
        return AjaxResult.success();
    }

}
